home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / source_code / dhtmlunl / dhtml.exe / CD Content / Chap15 / dun15_4.txt < prev    next >
Encoding:
Text File  |  1997-12-18  |  2.3 KB  |  76 lines

  1. <IMG NAME=arrow SRC="arrow.gif" ALIGN=left>
  2.  
  3.  
  4.  
  5. <DIV ID=banner STYLE="position: absolute; left: 72; top: 15;">
  6.  
  7.   <FONT FACE="Arial, Helvetica" SIZE=+2>
  8.  
  9.       Exposing Page Elements Cross-Browser
  10.  
  11.   </FONT>
  12.  
  13. </DIV>
  14.  
  15.  
  16.  
  17.  
  18.  
  19. <SCRIPT>
  20.  
  21. // reflectElements:
  22.  
  23. //
  24.  
  25. //   Reflects elements from the document.all collection up one
  26.  
  27. //   level to underneath the document object.
  28.  
  29. //
  30.  
  31. function reflectElements()
  32.  
  33. {
  34.  
  35.   for (var i=0; i<document.all.length; i++)
  36.  
  37.   {
  38.  
  39.     // If an element has an id and does not already exist
  40.  
  41.     // under the document object, reflect the element object
  42.  
  43.     // underneath the document object.
  44.  
  45.  
  46.  
  47.     if (document.all[i].id != "" &&
  48.  
  49.         !eval("document." + document.all[i].id))
  50.  
  51.     {
  52.  
  53.        eval("document." + document.all[i].id +
  54.  
  55.             " = document.all[" + i + "];");
  56.  
  57.     }
  58.  
  59.   }
  60.  
  61. }
  62.  
  63.  
  64.  
  65. // Detect if browser is IE4 and if so, reflect page elements up
  66.  
  67. // to document object.
  68.  
  69. //
  70.  
  71. if (navigator.appName.indexOf("Internet Explorer") != -1 &&
  72.  
  73.     navigator.appVersion.charAt(0) == '4')
  74.  
  75.       reflectElements();
  76.  
  77. </SCRIPT>
  78.  
  79.  
  80.  
  81.  
  82.  
  83. <BR><BR>
  84.  
  85. <P>The <TT>DIV</TT> element is normally reflected as
  86.  
  87. <TT>document.banner</TT> in Communicator 4.0 and
  88.  
  89. <TT>document.all['banner']</TT> in IE4.  Using this script to
  90.  
  91. manually reflect all named page elements beneath the document
  92.  
  93. object allows both browsers to access the <TT>DIV</TT> element using
  94.  
  95. <TT>document.banner</TT>.</P>
  96.  
  97.  
  98.  
  99. <P>The attributes of the <TT>DIV</TT> element that are reflected in both
  100.  
  101. browsers include:</P>
  102.  
  103.  
  104.  
  105. <BLOCKQUOTE>
  106.  
  107. <SCRIPT>
  108.  
  109.   document.writeln("<B>id:</B> " + document.banner.id + "<BR>");
  110.  
  111. </SCRIPT>
  112.  
  113. </BLOCKQUOTE>
  114.  
  115.  
  116.  
  117. <P>The <TT>IMG</TT> element is normally reflected as
  118.  
  119. <TT>document.arrow</TT> and <TT>document.images['arrow']</TT> in both
  120.  
  121. Communicator 4.0 and IE4.</P>
  122.  
  123.  
  124.  
  125. <P>The attributes of the <TT>IMG</TT> element that are reflected in both
  126.  
  127. browsers include:</P>
  128.  
  129.  
  130.  
  131. <BLOCKQUOTE>
  132.  
  133. <SCRIPT>
  134.  
  135.    document.writeln("<B>name:</B> " + document.arrow.name + "<BR>");
  136.  
  137.    document.writeln("<B>src:</B> " + document.arrow.src + "<BR>");
  138.  
  139.    document.writeln("<B>width:</B> " + document.images['arrow'].width +
  140.  
  141.                     "<BR>");
  142.  
  143.    document.writeln("<B>height:</B> " + document.images['arrow'].height +
  144.  
  145.                     "<BR>");
  146.  
  147. </SCRIPT>
  148.  
  149. </BLOCKQUOTE>
  150.  
  151.